package cn.flashapp.queue.listner;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import cn.flashapp.queue.Server;

import com.koolearn.util.SystemGlobals;

public class QueueListener implements ServletContextListener {
	private Server server = null;
	private List<String> list = null;

	private void init() {
		String cl = SystemGlobals.getPreference("queueReponsitory");
		if (cl == null)
			return;
		StringTokenizer st = new StringTokenizer(cl, ";");
		list = new ArrayList<String>();
		while (st.hasMoreTokens()) {
			list.add(st.nextToken());
		}
	}

	@SuppressWarnings("static-access")
	public void contextDestroyed(ServletContextEvent arg0) {

	}

	public void contextInitialized(ServletContextEvent arg0) {
		init();
		if ( list != null && (!list.isEmpty()) ) {
			server = new Server( list );
			server.start();
			System.out.println("queue is run");
		}
	}
}
